package cc.lj.internal.merchant.infrastructure.repository.mysql;

import cc.lj.internal.core.exception.ServiceException;
import cc.lj.internal.core.model.BasePageHelper;
import cc.lj.internal.merchant.domain.brand.repository.IMerchantBrandRelationRepository;
import cc.lj.internal.merchant.infrastructure.dao.IMerchantBrandRelationMapper;
import cc.lj.internal.merchant.infrastructure.exception.MerchantExceptionEnum;
import cc.lj.internal.merchant.infrastructure.po.MerchantBrandRelationPO;
import cc.lj.internal.merchant.infrastructure.po.PropertyRelationPO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 商户品牌关系表　Mysql仓储实现
 * @author liangxifeng
 * @date 2021-12-24
 */
@Slf4j
@Service(value = "merchantBrandRelationMysqlRespository")
public class MerchantBrandRelationMysqlRespository implements IMerchantBrandRelationRepository, BasePageHelper<MerchantBrandRelationPO> {
    @Autowired
    private IMerchantBrandRelationMapper relationMapper;

    @Override
    public List<MerchantBrandRelationPO> getList(MerchantBrandRelationPO merchantBrandRelationPO) {
        return list(merchantBrandRelationPO);
    }

    @Override
    public List<MerchantBrandRelationPO> list(MerchantBrandRelationPO param) {
        QueryWrapper<MerchantBrandRelationPO> wrapper = new QueryWrapper<>(param);
        List<MerchantBrandRelationPO> entitys = relationMapper.selectList(wrapper);
        if(entitys == null)
        {
            throw new ServiceException(MerchantExceptionEnum.MERCHNAT_BRAND_RELATION_LIST_NULL);
        }
        return entitys;
        //db_ljlj数据库的默认编码是latin1，数据是gbk编码方式的，因此需要转码
        //return entitys.stream().map(t -> transitionUtil.tst(t)).collect(Collectors.toList());
    }
}
